package com.edu.exam.entity.examination.paper;

import com.edu.exam.enums.AuditType;
import com.edu.exam.enums.AuditLevel;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * 特殊考试审核记录实体类
 * 所属模块：E-01 考试执行模块
 * 对应数据库表：special_exam_audit
 * 存储特殊考试申请的审核历史记录
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
public class SpecialExamAudit {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "application_id", referencedColumnName = "id", nullable = false, foreignKey = @ForeignKey(name = "fk_special_exam_audit_application"))
    private SpecialExamApplication application;

    @Column(name = "auditor_id", length = 64, nullable = false)
    private String auditorId;

    @Column(name = "auditor_name", length = 128)
    private String auditorName;

    @Column(name = "audit_type", length = 32, nullable = false)
    private String auditType;

    @Column(name = "audit_result", length = 32, nullable = false)
    private String auditResult;

    @Column(name = "audit_comment", columnDefinition = "TEXT")
    private String auditComment;

    @CreationTimestamp
    @Column(name = "audit_time", nullable = false, updatable = false)
    private LocalDateTime auditTime;

    @Column(name = "duration_seconds")
    private Integer durationSeconds;

    @Column(name = "previous_status", length = 32)
    private String previousStatus;

    @Column(name = "new_status", length = 32)
    private String newStatus;

    @Column(name = "ip_address", length = 45)
    private String ipAddress;

    @Column(name = "user_agent", length = 255)
    private String userAgent;

    @Column(name = "audit_level", length = 32)
    private String auditLevel;

    @Column(name = "delegate_reason", length = 255)
    private String delegateReason;

    @Column(name = "batch_id", length = 64)
    private String batchId;

    /**
     * 获取关联的申请ID
     */
    @Transient
    public Long getApplicationId() {
        return application != null ? application.getId() : null;
    }
}